/*
 * @Description:
 * @Author: 胡涛
 * @Date: 2023-09-26 09:04:12
 * @LastEditors: 胡涛
 * @LastEditTime: 2023-12-25 22:53:08
 */
interface IApplicationConfig {
  title?: string;
  loginTitle: string;
  copyright: string;
  logo?: string;
  icon?: string;
  description?: string;
  coverImage?: string;
  supportCompany: string;
  lastUpdateDate: string;
  version: string;
}

interface IGlobalConfig {
  previewHost: string;
  fileHost: string;
  /**
   * 应用配置
   */
  app: IApplicationConfig;
}

/**
 * 默认配置
 */
const defaultConfig: IGlobalConfig = {
  previewHost: "",
  fileHost: "",
  app: {
    title: "通用后台管理系统",
    loginTitle: "智能爆破方案设计-系统登录",
    copyright: "@2022 公司名称",
    supportCompany: "新疆三五九数字科技有限公司",
    version: "V1.0.0",
    lastUpdateDate: "2023-12 25 15:30",
  },
};

/**
 * 获取配置
 * @returns
 */
export const getGlobalConfig = (): IGlobalConfig => {
  let win = window as any;
  let config = win.globalConfig;
  let name = getEnvName();
  if (config && config[name]) {
    return config[name];
  } else {
    return defaultConfig;
  }
};

const getEnvName = () => {
  return "dev";
};

/**
 * 读取全局配置文件
 * @returns
 */
export const getApplicationConfig = (): IApplicationConfig => {
  let win = window as any;
  let config = win.globalConfig;
  if (config.app) {
    return config.app;
  }
  return getGlobalConfig().app;
};
